<?php

use Biz\model\Album\AlbumCategoryModel;
use Biz\service\Album\AlbumListService;
use Biz\service\Album\AlbumRecommendService;
use Doraemon\service\statSign\Basic as statSign;
use Doraemon\tools\BlockType;

/**
 * 清单广场头部
 */
class SquareHeadAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    /**
     * @throws \Exception
     */
    public function main()
    {
        $recommend = AlbumRecommendService::squareRecommend();
        $i = 1;
        foreach ($recommend as $key => $row) {
            $recommend[$key]['statSign'] = statSign::genStatSign(statSign::MODULE_GOOD_ALBUM_PAGE_ALBUM_LIST, [
                statSign::EXTEND_KEY_OBJ_ID => $row['album_info']['album_id'],
                statSign::EXTEND_KEY_OBJ_TYPE => BlockType::TYPE_WIKI_ALBUM,
                statSign::EXTEND_KEY_POS => 'top',
                statSign::EXTEND_KEY_INDEX => $i,
            ]);
            $i++;
        }
        $categoryArr = [
            [
                'category_id' => 0,
                'category_name' => '全部',
            ],
        ];
        $albumCategory = AlbumCategoryModel::selectByWhere([
            'status' => AlbumCategoryModel::STATUS_NORMAL,
            'ORDER' => ['sort' => 'ASC'],
        ], ['id', 'category_name']);
        foreach ($albumCategory as $item) {
            $categoryArr[] = [
                'category_id' => (int)$item['id'],
                'category_name' => $item['category_name'],
            ];
        }
        $this->setSuccess([
            'recommend' => $recommend,
            'album_category' => $categoryArr,
            'is_can_built_album' => AlbumListService::checkIsCanBuiltAlbum($this->uid),
        ]);
    }
}